package com.mlh.dp.old;

public class RingAndRod {
    public static void main(String[] args) {
        String rings="B0B6G0R6R0R6G9";
        System.out.println(method1( rings));
    }
    public static int method1(String rings){
        //这题很简单  不用什么DP
        //创建一个二维数组就可以解决问题
        int rodNum=0;//满足要求的杆数量
        int[][]rods=new int[10][4];//10是杆的数量   0列代表杆上套了几个换  123列分别代表是否有套RGB的环
        char[]ring=rings.toCharArray();
        for(int i=0;i<ring.length;i+=2){
            if('R'==ring[i]){
                int num=Character.getNumericValue(ring[i+1]);
                rods[num][0]+=1;
                rods[num][1]=1;
                continue;
            }else if('G'==ring[i]) {
                int num=Character.getNumericValue(ring[i+1]);
                rods[num][0]+=1;
                rods[num][2]=1;
                continue;
            }else if('B'==ring[i]){
                int num=Character.getNumericValue(ring[i+1]);
                rods[num][0]+=1;
                rods[num][3]=1;
                continue;
            }
        }
        //遍历二维数组，寻找满足条件的杆
        for(int j=0;j<10;j++){
            if(rods[j][0]>=3){
                if(rods[j][1]==1&&rods[j][2]==1&&rods[j][3]==1){
                    rodNum+=1;
                }
            }
        }
        //返回结果
        return rodNum;
    }
}
